package com.tedu.weibo.common.result;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/*
* int status:状态代码 用于表示处理的不同结果
* String msg:描述信息,用于描述处理结果(可用于现用户做提示)
* Object data:数据 向前端发送的处理结果数据(可能是单一值,可能是一个VO)
*
* */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer status;
    private String msg;

    private Object data;

    public JsonResult(StatusCode statusCode) {
        this.status = statusCode.getStatusCode();
        this.msg = statusCode.getMessage();
    }

    public JsonResult(StatusCode statusCode,Object data) {
        /*this.status = statusCode.getStatusCode();
        this.msg = statusCode.getMessage();*/
        this(statusCode);//调用本类的JsonResult(StatusCode statusCode)复用构造器的初始化操作
        this.data = data;
    }

    public static JsonResult success(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public static JsonResult success(){
        // return new JsonResult(StatusCode.OPERATION_SUCCESS,null);
        return success(null);
    }

}
